<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>

<?php 
	$ci = &get_instance();
	$USER = getAccountUserObject();
	$escort_id = intval($this->input->get('escort_id',TRUE));
	$ESCORT = $ci->escort_entity->init('id',$escort_id);
	$LOCKED = $ci->locked_escort_entity->init('escort_id', $ESCORT->getId());
	
	$geoArray = explode('#', $ESCORT->getGeolocation());
	$lat = count($geoArray)==2 ? $geoArray[0] :'0';
	$lng = count($geoArray)==2 ? $geoArray[1] :'0';
?>


<form action="<?php echo site_url('agent/escort/submit_contact_info');?>" name="submit_contact_info" id="submit_contact_info" method="post" enctype="multipart/form-data" >
	<input type="hidden" value="<?php echo $lat;?>" name="contact_lat" id="contact_lat" />
	<input type="hidden" value="<?php echo $lng;?>" name="contact_lng" id="contact_lng" />
	<input type="hidden" name="escort_id" value="<?php echo $escort_id;?>" />
	
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left">
			<span><?php echo language_translate('contact_info_name');?></span>
			<div class="help-text" title="<?php echo language_translate('contact_info_name_hint');?>"></div>	
		</div>
		<div class="dashboard-info-right">
			<div class="select-box">
				<input type="text" name="contact_info_name" id="contact_info_name" value="<?php echo $ESCORT->getEscortName();?>" maxlength="45" class="text-box3">
			</div>
			<div class="input-error" id="contact_info_name_err" >&nbsp;</div>
			
			<div class="clear"></div>
		</div>
		<div class="clear"></div>
	</div>
	
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left">
			<span><?php echo language_translate('contact_info_phone');?></span>
			<div class="help-text" title="<?php echo language_translate('contact_info_phone_hint');?>"></div>
		</div>
		<div class="dashboard-info-right">
			<div class="select-box">
				<input type="text" name="contact_info_phone" id="contact_info_phone" value="<?php echo $ESCORT->getEscortPhone();?>" maxlength="15" class="text-box3">
			</div>
			<div class="input-error" id="contact_info_phone_err" >&nbsp;</div>
			<div class="input-box" style="margin-right: 0px;">
				<input type="checkbox" onoff="1" value="1" name="contact_info_public_phone" class="custom" 
					<?php echo $ESCORT->getPublicPhone() == 1 ? "checked='checked'":''; ?> />
			</div>
			
			<?php if($LOCKED->getLockedPhone() == 1):?>
				<div class="locked"></div>
			<?php endif;?>
			
			<div class="clear"></div>
		</div>
		<div class="clear"></div>
	</div>
	
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left">
			<span><?php echo language_translate('contact_info_email');?></span>
			<div class="help-text" title="<?php echo language_translate('contact_info_email_hint');?>"></div>
		</div>
		<div class="dashboard-info-right">
			<div class="select-box">
				<input type="text" name="contact_info_email" id="contact_info_email" value="<?php echo $ESCORT->getEscortEmail();?>" maxlength="45" class="text-box3">
			</div>
			<div class="input-error" id="contact_info_email_err">&nbsp;</div>
			<div class="input-box" style="margin-right: 0px;">
				<input type="checkbox" onoff="1" value="1" name="contact_info_public_email" class="custom" 
					<?php echo $ESCORT->getPublicEmail() == 1 ? "checked='checked'":''; ?> />
			</div>
			
			<?php if($LOCKED->getLockedEmail() == 1):?>
				<div class="locked"></div>
			<?php endif;?>
			
			<div class="clear"></div>
		</div>
		<div class="clear"></div>
	</div>
	
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left">
			<span><?php echo language_translate('contact_info_address');?></span>
			<div class="help-text" title="<?php echo language_translate('contact_info_address_hint');?>"></div>
		</div>
		<div class="dashboard-info-right">
			<div class="select-box">
				<input type="text" name="contact_info_address" id="contact_info_address" value="<?php echo $ESCORT->getEscortAddress();?>" maxlength="255" class="text-box3">
			</div>
			<div class="input-error" id="contact_info_address_err">&nbsp;</div>
			<div class="input-box" style="margin-right: 0px;">
				<input type="checkbox" onoff="1" value="1" name="contact_info_public_address" class="custom" 
					<?php echo $ESCORT->getPublicAddress() == 1 ? "checked='checked'":''; ?> />
			</div>
			
			<?php if($LOCKED->getLockedAddress() == 1):?>
				<div class="locked"></div>
			<?php endif;?>
			
			<div class="clear"></div>
			<input type="button" class="save-button" id="findLocation" style="margin-top:3px;" value="<?php echo language_translate('contact_info_find_location');?>" /> 
			
		</div>
		<div class="clear"></div>
	</div>
	
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left"><span><?php echo language_translate('contact_info_geolocalization');?></span></div>
		<div class="dashboard-info-right">
			<div class="select-box">
				<a href="javascript:void(0);" onclick="javascript:return getGeolocation();" ><?php echo language_translate('contact_info_geolocalization_now');?></a> 
			</div>	
			<div class="input-box">
				<input type="checkbox" onoff="1" value="1" name="contact_info_public_geolocalization" class="custom" 
					<?php echo $ESCORT->getPublicGeolocation() == 1 ? "checked='checked'":''; ?> />
			</div>
			<?php if($LOCKED->getLockedGeolocation() == 1):?>
				<div class="locked"></div>
			<?php endif;?>
			
			<div class="clear"></div>
		</div>
		<div class="clear"></div>
	</div>
	
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left"><span><?php echo language_translate('contact_info_show_map');?></span></div>
		<div class="dashboard-info-right">
			<div id="google_map_add_form" style="width:350px;height:350px;"></div> 
			<div class="clear"></div>
		</div>
		<div class="clear"></div>
	</div>
	
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left"><span><?php echo language_translate('contact_info_show_address');?></span></div>
		<div class="dashboard-info-right">
			<div class="input-box">
				<input type="checkbox" onoff="1" value="1" name="contact_info_show_address_on_map" class="custom" 
					<?php echo $ESCORT->getShowAddressOnMap() == 1 ? "checked='checked'":''; ?> />
			</div>
			
			<?php if($LOCKED->getLockedMap() == 1):?>
				<div class="locked"></div>
			<?php endif;?>
			<div class="clear"></div>
		</div>
		<div class="clear"></div>
	</div>
	
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left"><span><?php echo language_translate('contact_info_receive_message');?></span></div>
		<div class="dashboard-info-right">
			<div class="input-box">
				<input type="checkbox" onoff="1" value="1" name="contact_info_receive_message" class="custom" 
					<?php echo $ESCORT->getReceiveMessage() == 1 ? "checked='checked'":''; ?> />
			</div>
			<div class="clear"></div>
		</div>
		<div class="clear"></div>
	</div>
	
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left"> 
			<div class="select-box">
				<input type="submit" class="save-button" value="<?php echo language_translate('contact_info_save');?>" /> 
			</div>
		 </div>
		 <div class="dashboard-info-right">
			<?php echo loader_image("id='contact_info_loader_image' class='hidden'");?>
		</div>
		<div class="clear"></div>
	</div>	

	<div class="dashboard-info-wrapper">
		<div id="update-message"><?php echo language_translate('update_successfully_message');?></div>
		<div class="clear"></div>
	</div>
	
</form>

<script type="text/javascript">
$(document).ready(function() {	
	var options = { 
		beforeSubmit:  validateB4SubmitContactInfo,  
		success:       processAfterRespondingContactInfo   
	};	
	$('#submit_contact_info').ajaxForm(options); 
	initialize(<?php echo $lat ;?>,<?php echo $lng ;?>);
	$('#findLocation').bind('click',function(){codeAddress();});
	$('.help-text[title]').qtip({ style: { name: 'dark', tip: true } });
});	
function validateB4SubmitContactInfo(formData, jqForm, options){
	$('#contact_info_loader_image').show();
	return true;
}

function processAfterRespondingContactInfo(responseText, statusText, xhr, $form) {
	$('#contact_info_loader_image').hide();	
	if(responseText == 'ok'){
		updatedShow();
	}else{
		debug(responseText);
		var arr_res = responseText.split('#');
		$('#'+arr_res[0]).html(arr_res[1]);
	}
}

function codeAddress() {
    var address = document.getElementById("contact_info_address").value;
    geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        map.setCenter(results[0].geometry.location);
         marker = new google.maps.Marker({
            map: map, 
            position: results[0].geometry.location
        });
        var pos = results[0].geometry.location; 
        $('#contact_lat').attr('value', pos.$a ); 
        $('#contact_lng').attr('value', pos.ab );      
      } else {
        
      }
    });
  }

function success(position) {
  var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
  var myOptions = {
    zoom: 14,
    center: latlng,
    mapTypeControl: true,
    navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  var map = new google.maps.Map(document.getElementById("google_map_add_form"), myOptions);
 
  google.maps.event.addListener(map, 'click', function(event) {
    mapEditor(event.latLng);
  });
  marker = new google.maps.Marker({
	position: latlng,
	map: map
  });
   $('#contact_lat').attr('value', position.coords.latitude ); 
   $('#contact_lng').attr('value', position.coords.longitude ); 
}

function error(msg) {
	debug(msg);
}

function getGeolocation(){
	if (navigator.geolocation) {
	  navigator.geolocation.getCurrentPosition(success, error);
	} else {
	   debug('not supportted');
	}
}
</script>		